package com.wanmao.test.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.wanmao.test.R;
import com.wanmao.test.model.InstitutionModel;

import java.util.List;


public class InstitutionAdapter extends BaseAdapter {
    Context context;
    InstitutionModel.TabsBean bean;
    List<InstitutionModel.TabsBean.ContentBean> list;
    LayoutInflater layoutInflater;

    public InstitutionAdapter(Context context, InstitutionModel.TabsBean bean) {
        this.context = context;
        this.bean = bean;
        this.list = bean.getContent();
        layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return null == list ? 0 : list.size();
    }

    @Override
    public InstitutionModel.TabsBean.ContentBean getItem(int position) {
        return null == list ? null : list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (null == convertView) {
            convertView = layoutInflater.inflate(R.layout.item_institution_list, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.init(bean, position);
        return convertView;
    }

    class ViewHolder {
        TextView step, performance, project;

        public ViewHolder(View convertView) {
            step = (TextView) convertView.findViewById(R.id.tv_step);
            performance = (TextView)convertView.findViewById(R.id.tv_performance);
            project = (TextView)convertView.findViewById(R.id.tv_project);
        }

        public void init(InstitutionModel.TabsBean bean, int position) {
            InstitutionModel.TabsBean.ContentBean item = getItem(position);
            step.setText(bean.getStep());
            String prStr=item.getPerformance();
            if(prStr==null){
                prStr="数据错误";
            }
            performance.setText(item.getPerformance());
            project.setText(item.getProject());
        }
    }
}
